<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="name" label="栏目名称" ></el-table-column>
      <el-table-column label="状态" width="250">
        <template slot-scope="scope">
          <el-switch 
                     v-model="scope.row.on" 
                     active-value="1"
                     inactive-value="0"
                     active-color="#13ce66"
                     @change="changeSwitch(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" class="editButton" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" class="addButton" @click="AddleEdit(scope.$index, scope.row)">添加子栏目</el-button>
          <el-button size="mini" class="deleteButton" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [
        {
          id: 1,
          name: "首页",
          children: [
              {
                  id:11,
                  name: "新闻页"
              }
          ]
        },
        {
          id: 2,
          name: "关于我们",
          children: [
            {
              id: 21,
              name: "国际学院概况",
            },
            {
              id: 22,
              name: "院长寄语",
            },
            {
              id: 23,
              name: "机构设置",
            }
          ]
        },
        {
          id: 3,
          name: "留学川农",
          children: [
            {
              id: 31,
              name: "研究生项目",
            },
            {
              id: 32,
              name: "本科生项目",
            }
          ]
        },
        {
          id: 4,
          name: "合作办学",
          children:[
              {
                  id:41,
                  name:"项目专栏",
              },
              {
                  id:42,
                  name:"申请流程",
              },
          ]
        },
        {
          id: 5,
          name: "培训中心",
          children: [
              {
                  id:51,
                  name: "中心概况",
              },
               {
                  id:52,
                  name: "项目宣传",
              },
          ]
        },
        {
          id: 6,
          name: "校园生活",
          children: [
              {
                  id:61,
                  name: "校园活动",
              },
               {
                  id:62,
                  name: "学院风采",
              },
          ]
        },
        {
          id: 7,
          name: "联系我们",
            children: [
              {
                  id:71,
                  name: "联系方式",
              },
          ]
        }
      ],
      value: '1',
    };
  },
  methods: {
      changeSwitch(data) {
          console.log(data)
      }
  }
};
</script>
<style>
.editButton{
    background-color: #67c23a;
    color: white;
}
.addButton{
    background-color: orange;
    color: white;
}
.deleteButton{
    background-color:#f56c6c;
    color: white;
}
</style>